package org.linlinjava.litemall.admin.service;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.admin.dto.GoodsAllinone;
import org.linlinjava.litemall.admin.vo.CatVo;
import org.linlinjava.litemall.core.qcode.QCodeService;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.linlinjava.litemall.admin.util.AdminResponseCode.GOODS_NAME_EXIST;

@Service
public class AdminActorService {
    private final Log logger = LogFactory.getLog(AdminActorService.class);

    @Autowired
    private LitemallGoodsService goodsService;
    @Autowired
    private LitemallGoodsSpecificationService specificationService;
    @Autowired
    private LitemallGoodsAttributeService attributeService;
    @Autowired
    private LitemallGoodsProductService productService;
    @Autowired
    private LitemallCategoryService categoryService;
    @Autowired
    private LitemallBrandService brandService;
    @Autowired
    private LitemallCartService cartService;
    @Autowired
    private QCodeService qCodeService;
    @Autowired
    private LemonlaActorService actorService;

    public Object list(Integer actorId, String name, String nickname,
                       Integer page, Integer limit, String sort, String order) {
        List<LemonlaActor> goodsList = actorService.querySelective(actorId, name, nickname, page, limit, sort, order);
        return ResponseUtil.okList(goodsList);
    }

    @Transactional
    public Object update(LemonlaActor actor) {
        actorService.update(actor);
        return ResponseUtil.ok();
    }

    @Transactional
    public Object delete(LemonlaActor actor) {
        Integer id = actor.getId();
        if (id == null) {
            return ResponseUtil.badArgument();
        }

        Integer actorId = actor.getId();
        actorService.deleteById(actorId);

        return ResponseUtil.ok();
    }

    public Object create(LemonlaActor actor) {
        actorService.add(actor);
        return ResponseUtil.ok(actor);
    }

    public Object detail(Integer id) {
        LemonlaActor byIdWithDes = actorService.findByIdWithDes(id);
        return ResponseUtil.ok(byIdWithDes);
    }
}
